<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('资源管理列表')" />
    <th:block th:include="include :: datetimepicker-css" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <p>资源名称：</p>
                                <input type="text" name="resourceName"/>
                            </li>
                            <li>
                                <p>资源类型：</p>
                                <select name="type" th:with="type=${@dict.getType('web_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li style="display: flex;">
                                <span>所属课程：</span>
                                <div class="input-group">
                                    <input type="hidden" name="courseId" id="courseName">
                                    <input class="form-control" id="suggest-demo-1" style="width:274px;"required>
                                    <div class="input-group-btn">
                                        <button type="button" class="btn btn-white dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu dropdown-menu-right" role="menu">
                                        </ul>
                                    </div>
                                </div>

                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:explorer:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:explorer:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:explorer:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:explorer:export">
                    <i class="fa fa-download"></i> 导出
                 </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
     <th:block th:include="include :: datetimepicker-js" />
     <th:block th:include="include :: bootstrap-suggest-js" />
     <th:block th:include="include :: bootstrap-typeahead-js" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:explorer:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:explorer:remove')}]];
        var editFlag2 = [[${@permission.hasPermi('system:explorer:download')}]];
        var prefix = ctx + "system/explorer";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "资源管理",
                columns: [{
                    checkbox: true
                },
                {
                    field : 'id', 
                    title : '序号',
                    visible: true,
                    formatter: function (value, row, index) {
                        return $.table.serialNumber(index);
                    }
                },
                {
                    field : 'resourceName', 
                    title : '资源名称'
                },
                {
                    field : 'type', 
                    title : '资源类型',
                    formatter: function (value, row, index) {
                        if(value==1){
                            return value="虚拟仿真实验";
                        }else{
                            return value="实物实验";
                        }
                    }
                },
                {
                    field : 'courseName',
                    title : '所属课程'
                },
                {
                    field : 'createTime',
                    title : '上传日期'
                },
                {
                    field : 'userName',
                    title : '上传人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag2 + '" href="javascript:void(0)" onclick="downloadFile(\'' + row.path + '\')"><i class="fa fa-edit"></i>下载</a> ');
                        // actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        var testBsSuggest = $("#suggest-demo-1").bsSuggest({
            url: ctx + "website/totalcourse/searchSelect",
            effectiveFields: ["courseName"],
            effectiveFieldsAlias:{courseName: "课程名称"},
            showBtn: false,
            idField: "id",
            keyField: "courseName",
        }).on('onSetSelectValue', function (e, keyword) {
            $("#courseName").val(keyword.id);
        });

        function downloadFile(value){
            $.modal.confirm("确认要下载吗?", function() {
                window.location.href = ctx + "common/download/resource/?resource=" + value;
            });
        }

        function reset(){
            $.modal.reload();
        }

    </script>
</body>
</html>